using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Collections;
using System.Data;
using System.Diagnostics;
using System.IO;
using MyClever.Lib;

namespace MyClever.DefaultPlugins
{
    public class ReadFileContent : MissionPlugin
    {
        [Package(Direction.Input, "Defines the file, you like to read the content from.")]
        enum ReadableFile
        {
            [Column(typeof(string), "The file you like to process? (*.exe)",
                Validation="isexistingfile")]
            FilePath
        }

        [Package(Direction.Output, "Defines the content of the given files.")]
        enum FileOutput
        {
            [Column(typeof(string), "Path of the file, we have read the content from.")]
            Path,
            [Column(typeof(string), "The content of the file.")]
            Content
        }

        [Plugin(PluginDevStatus.Production, "Reading text data from expected files.")]
        public ReadFileContent()
        {
        }

        public override void Initialize()
        {
            
            //This is the first Function called by the host...
            //Put anything needed to start with here first
        }

        public override void Dispose()
        {
            //Put any cleanup code in here for when the program is stopped
        }

        /// <summary>
        /// Generate new Source-content.
        /// </summary>
        protected override void Work()
        {
            DataTableReader filesToRead = this.GetDataReader(typeof(ReadableFile));
            while (filesToRead.Read())
            {
                this.AddNewLoggingMessage(typeof(ReadableFile), String.Format("read content from :{0}", filesToRead[ReadableFile.FilePath.ToString()].ToString()));

                string fileContent = System.IO.File.ReadAllText(filesToRead[ReadableFile.FilePath.ToString()].ToString());

                DataRow newRow = this.CreateNewRowFromPackage(typeof(FileOutput));
                newRow[FileOutput.Path.ToString()] = filesToRead[ReadableFile.FilePath.ToString()].ToString();
                newRow[FileOutput.Content.ToString()] = fileContent;
                this.AddNewRowToPackage(typeof(FileOutput), newRow);
            }
        }
    }
}
